package com.bluegalaxy.nhb.snapi.core.common;

import com.bluegalaxy.nhb.snservice.core.util.ObjectUtil;
import com.bluegalaxy.nhb.snservice.domain.vo.api.ck.OvervivwVO;
import com.bluegalaxy.nhb.snservice.domain.vo.api.ck.SpreadVO;

import java.math.BigDecimal;
import java.util.*;

public class OvervivwUtil {


    private static Map<String,Long> map = new HashMap<>();

    public static Long get(String key) {
        return map.get(key);
    }

    public static void put(String key, long value) {
        map.put(key,value);
    }

    public static void supplementList(List<OvervivwVO> overvivwVOList, List<String> dateList){
        overvivwVOList = overvivwVOList==null? new ArrayList<>():overvivwVOList;

        for (String st:dateList){
            if(!isContain(st,overvivwVOList)){

                overvivwVOList.add(initVO(st));
            }
        }
    }

    public static OvervivwVO initVO(String eventDate){
        OvervivwVO overvivwVO=new OvervivwVO();
        overvivwVO.setEventDate(eventDate);
        overvivwVO.setEventCount("0");
        overvivwVO.setComparison("0");
        overvivwVO.setEventAmount(BigDecimal.ZERO);
        overvivwVO.setCombineCount(0);
        overvivwVO.setOnyearFlow("0");
        return overvivwVO;
    }

    public  static Boolean  isContain(String t,List<OvervivwVO> overvivwVOList){
        Boolean isContain= false;
        for (OvervivwVO overvivwVO:overvivwVOList){
            if(t.equals(overvivwVO.getEventDate())){
                isContain= true;
                break;
            }
        }
        return isContain;
    }

    public static OvervivwVO getOvervivwVO(String eventDate,List<OvervivwVO> overviewList){
        Optional<OvervivwVO> optional = overviewList.stream().filter(property -> property.getEventDate().equals(eventDate)).findFirst();
        if (optional.isPresent()) {
            // 存在
            OvervivwVO so =  optional.get();
            return so;
        } else {
            // 不存在
        }
        return initVO(eventDate);
    }

    public static SpreadVO getSpreadVO(String eventDate, List<SpreadVO> overviewList){
        Optional<SpreadVO> optional = overviewList.stream().filter(property -> property.getEventDate().equals(eventDate)).findFirst();
        if (optional.isPresent()) {
            // 存在
            SpreadVO so =  optional.get();
            return so;
        } else {
            // 不存在
        }
        return null;
    }

    public static Integer getCombineEventCount(String eventName,String eventDate,List<OvervivwVO> combineList){
        if (Objects.isNull(combineList) || combineList.isEmpty()){
            return 0;
        }
        Optional<OvervivwVO> optional = combineList.stream().filter(property -> property.getEventDate().equals(eventDate) && property.getEventName().equals(eventName)).findFirst();
        if (optional.isPresent()) {
            // 存在
            OvervivwVO so =  optional.get();
            return so.getCombineCount();
        } else {
            // 不存在
        }
        return 0;
    }
}
